import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:pornhub_app/assets/styles.dart';
import 'package:pornhub_app/components/no_more/no_data.dart';
import 'package:pornhub_app/generate/app_image_path.dart';
import 'package:pornhub_app/model/video_base_model.dart';
import 'package:pornhub_app/routes/routes.dart';
import 'package:pornhub_app/utils/extension.dart';
import 'package:pornhub_app/utils/utils.dart';

import '../../http/api/api.dart';
import '../../utils/color.dart';

class RainBowHotPage extends StatefulWidget {
  const RainBowHotPage({super.key});

  @override
  State<StatefulWidget> createState() => _State();
}

class _State extends State<RainBowHotPage> {
  List<VideoBaseModel> list = [];
  @override
  void initState() {
    getHotsList();
    super.initState();
  }

  Future<void> getHotsList() async {
    final resp = await Api.fetchRainBowhots();
    if (resp != null) {
      setState(() {
        list = resp;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(
        slivers: [
          SizedBox(
            height: 200.w,
            child: Image.asset(
              AppImagePath.short_short_hots_bg,
              width: double.infinity,
              height: 200.w,
            ),
          ).sliver,
          list.isEmpty
              ? const NoData.empty().sliver
              : SliverList.builder(
                  itemCount: list.length,
                  itemBuilder: (context, index) {
                    final item = list[index];
                    return SizedBox(
                      width: double.infinity,
                      height: 45.w,
                      child: Row(
                        mainAxisSize: MainAxisSize.max,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Text('${index + 1}.',
                              style: kTextStyle(index < 3
                                  ? COLOR.hexColor("#FFE049")
                                  : COLOR.hexColor("#8F8F8F"))),
                          SizedBox(width: 6.w),
                          Expanded(
                            child: Text(
                              item.title ?? '',
                              textAlign: TextAlign.left,
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                              style: kTextStyle(Colors.white),
                            ),
                          ),
                          SizedBox(width: 6.w),
                          Image.asset(AppImagePath.short_short_hot_icon,
                              width: 20.w, fit: BoxFit.fitWidth),
                          SizedBox(width: 6.w),
                          SizedBox(
                            width: 35.w,
                            child: Text(
                              Utils.numFmt(item.fakeWatchNum ?? 0),
                              textAlign: TextAlign.left,
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                              style: kTextStyle(Colors.white),
                            ),
                          ),
                        ],
                      ).paddingHorizontal(12.w),
                    ).onTap(() {
                      Get.toShortVideoPlay(list, idx: index);
                    });
                  },
                ),
        ],
      ),
    );
  }
}
